//支付记录
import 'package:flutter/material.dart';
import 'package:untitled1/app/broker/modules/employer/EmployerDetailPage.dart';
import 'package:untitled1/app/utils/utilRouter.dart';
import 'package:untitled1/app/widgets/TitleBar.dart';

import '../../../res/myColors.dart';
import '../../../widgets/base_page/BaseStatefulPage.dart';
import '../serve/ServeDetailPage.dart';
import 'PayRecordPage.dart';

// 订单详情
class OrderDetailPage extends BaseStatefulPage {
  @override
  BaseStatefulPageState<BaseStatefulPage> createState() =>
      _OrderDetailPageState();
}

class _OrderDetailPageState extends BaseStatefulPageState<OrderDetailPage> {
  @override
  Widget buildPage(BuildContext context) {
    return Scaffold(
      appBar: TitleBar(title: '订单详情'),
      body: Container(
        color: myColors.white,
        child: Stack(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Divider(height: 1, color: myColors.divider),
                Container(
                  margin: EdgeInsets.only(left: 15, right: 15, top: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '家员私厨',
                        style: TextStyle(
                          fontSize: 16,
                          color: myColors.c_191919,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          showPay();
                        },
                        child: Text(
                          '已支付',
                          style: TextStyle(
                            fontSize: 16,
                            color: myColors.c_FF4142,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                buildItem(
                  '雇主',
                  '张珊珊',
                  onTap: () {
                    utilRouter.to(EmployerDetailPage());
                  },
                ),
                buildItem(
                  '服务人员',
                  '张珊珊',
                  onTap: () {
                    utilRouter.to(ServeDetailPage());
                  },
                ),
                buildItem('经济人', '张珊珊'),
                buildItem('订单类型', '服务费'),
                buildItem('支付身份', '服务人员'),
                buildItem('订单编号', 'xxxxxx'),
                buildItem('订单金额', '0元'),
                buildItem('购买数量', '1'),
                buildItem('付款方式', '在线支付'),
                buildItem('支付形式', '一次性支付'),
                buildItem('已收金额', '0元'),
                SizedBox(height: 10),
                buildItem('下单时间', '2025.08.08'),
                buildItem('付清时间', '2025.09.08'),
                SizedBox(height: 10),
                buildItem(
                  '合同编号',
                  'xxxxx',
                  onTap: () {
                    //关联合同
                  },
                ),
                buildItem('订单状态', 'xxxxx'),
                buildItem('待支付状态', 'xxxxx'),
                buildItem('已付清状态', 'xxxxx'),
                // buildItem('付款方式', '一次性支付'),
              ],
            ),
            Positioned(
              left: 0,
              right: 0,
              bottom: 0,
              child: getFootBox(context),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildItem(
    String title,
    String content, {
    String? type,
    GestureTapCallback? onTap,
  }) {
    return InkWell(
      onTap: () {
        onTap?.call();
      },
      child: Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 5),
        child: Text(
          '${title}：${content}',
          style: TextStyle(fontSize: 14, color: myColors.c_707070),
        ),
      ),
    );
  }

  Widget getFootBox(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      color: myColors.white,
      padding: EdgeInsets.only(left: 15, right: 15, bottom: 20),
      child: Column(
        children: [
          // Text('aaaa'),
          Container(
            color: myColors.white,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              children: [
                // 左侧按钮们：退单、记录、待分享、完善信息、打电话
                // Row(children: getFootTexts()),

                // 右侧按钮们
                Expanded(
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    children: getFootButtons(context),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  List<Widget> getFootButtons(BuildContext context) {
    if (1 == 1) {
      return [
        Expanded(child: _buildSolidButton(context, '取消订单')),
        // Expanded(child: _buildSolidButton('查看合同')),
        // Expanded(child: _buildSolidButton('缴纳服务费')),
      ];

      // _buildVerticalButton('代收薪资', '本期付清'),
    } else if (1 == 2) {
      return [
        // Expanded(child: _buildSolidButton('取消订单')),
        // Expanded(child: _buildSolidButton('查看合同')),
        // Expanded(child: _buildSolidButton('缴纳定金')),
      ];
    } else if (1 == 2) {
      return [
        // Expanded(child: _buildSolidButton('取消订单')),
        // Expanded(child: _buildSolidButton('查看合同')),
        // Expanded(child: _buildSolidButton('缴纳尾款')),
      ];
    } else if (1 == 2) {
      return [
        // Expanded(child: _buildSolidButton('取消订单')),
        // Expanded(child: _buildSolidButton('去支付')),
      ];
    }
    return [];
  }

  showPay() {
    showDialog(
      context: context,
      barrierDismissible: false, // 点击空白区域不关闭
      builder: (context) {
        return Dialog(
          insetPadding: EdgeInsets.zero, // 去除默认 margin
          backgroundColor: Colors.transparent, // 让背景透明（我们内容自己决定样式）
          child: PayRecordPage(), // 就是你的弹出框内容
        );
      },
    );
  }

  Widget _buildSolidButton(BuildContext context, String text) {
    return InkWell(
      onTap: () {},
      child: Container(
        width: 80,
        height: 40,
        alignment: Alignment.center,
        margin: const EdgeInsets.only(left: 8),
        decoration: BoxDecoration(
          color: const Color(0xFFFF4142),
          border: Border.all(color: Color(0xFFFF4142)),
          borderRadius: BorderRadius.circular(50),
        ),
        child: Text(
          text,
          style: const TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.bold,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}
